<template>
	<div id="">
		<span id="1" style="display: none;">
			{{current.userId}}
		</span>
		
		<div class="updatep">
			<h3>我的信息</h3>
			<van-form @submit="onSubmit">
			  <van-field
			    v-model="user.account"
			    name="账号"
			    label="账号"
			    placeholder="账号"
			  />
			  <van-field
			    v-model="user.nickName"
			    name="昵称"
			    label="昵称"
			    placeholder="昵称"
			  />
			  <van-field
			    v-model="user.age"
			    name="年龄"
			    label="年龄"
			    placeholder="年龄"
			  />
			  <van-field
			    v-model="user.sex"
			    name="性别"
			    label="性别"
			    placeholder="性别"
			  />
			  <van-field
			    v-model="user.tel"
			    name="电话号码"
			    label="电话号码"
			    placeholder="电话号码"
			  />
			  <van-field
			    v-model="user.secId"
			    name="身份证号"
			    label="身份证号"
			    placeholder="身份证号"
			  />
			  <van-field
			    v-model="upassword"
			    name="新密码"
			    label="新密码"
			    placeholder="新密码"
			    :rules="[{ required: true, message: '请填写新密码'},{ pattern: /\d{6}/,message: '密码至少为6位',trigger: 'onBlur'}]"
			  />
			  <van-field
			    v-model="confirmpassword "
			    type="password"
			    name="确认密码"
			    label="确认密码"
			    placeholder="确认密码"
			    :rules="[{ required: true, message: '请确认密码' },{ pattern: /\d{6}/,message: '密码至少为6位',trigger: 'onBlur'}]"
			  />
			  <div style="margin: 16px;">
			    <van-button round block type="info" native-type="submit">提交</van-button>
			  </div>
			</van-form>
		</div>
		<tabbar></tabbar>
		<div style="height: 3rem;"></div>
	</div>
	
</template>

<script>
	import tabbar from '../../src/components/tarbar.vue'
	import store from '../../common/store.js'
	import { Toast } from 'vant';
	export default {
	  data() {
	    return {
	     userId:'',
	     currentUser:{},
		 student:{},
		 upassword:'',
		 confirmpassword:'',
		 userId:'',
		 user:{
			 userId:'',
			 account:'',
			 nickName:'',
			 age: '',
			 sex: '',
			 tel: '',
			 secId: '',
			 password:''
		 }
	    };
	  },
	  components: {
	    tabbar,
	  },
	  methods:{
		  logout: () => {
		  	store.commit('loginOut')
		  },
		  search:function(){
			  this.http
			      .get({
					  url:`/system/student/info/${this.$data.userId}`
				  }).then((data)=>{
					  this.$data.user.userId = data.user.userId
					  this.$data.user.account = data.user.account
					  this.$data.user.nickName = data.user.nickName
					  this.$data.user.age = data.user.age
					  this.$data.user.sex = data.user.sex
					  this.$data.user.tel = data.user.tel
					  this.$data.user.secId = data.user.secId
					  this.$data.student = data.student
				  })
		  },
		  onSubmit:function(){
			  if(this.$data.upassword != this.$data.confirmpassword){
			  	Toast("两次输入不一致")
			  }else if(this.$data.upassword == this.$data.confirmpassword){
				      this.$data.user.password = this.$data.upassword
		  			  this.http
		  			      .put({
		  					  url:'/system/student/info/update',
		  					  param:{
		  						  studentStr : this.$data.student,
		  						  userStr : this.$data.user
		  					  }
		  				  }).then((data) => {
							  Toast.success("修改成功")
							  this.search()
		  				  })
		  			  }
		  }
	  },
	  mounted() {
	  	this.$data.userId = this.$data.currentUser.user.userId
		this.search()
	  },
	  computed: {
	  	current: function() {
	  		this.$data.currentUser = store.state.currentUser
	  		return store.state.currentUser
	  	},
	  },
	};
	
</script>


<style scoped>
	.updatep h3{
		margin:10px;
		text-align: center;
		
	}
</style>
